<form id="password" class="form form-align clear" action="#" name="password-form" method="post">
    <p class="field">
        <label for="old">旧密码</label>
        <input id="old" type="password" name="old" required="required" class="ipt"/>
        <span class="tip">验证旧密码</span><br/>
        <span class="invalid lbl lbl-red hide" id="old-invalid">密码长度4-20个字符</span>
    </p>
    <p class="field">
        <label for="new">新密码</label>
        <input id="new" type="password" name="new" required="required" class="ipt"/><br/>
        <span class="invalid lbl lbl-red hide" id="new-invalid">密码长度4-20个字符</span>
    </p>
    <p class="field">
        <label for="confirm">确认密码</label>
        <input id="confirm" type="password" name="confirm" required="required" class="ipt"/><br/>
        <span class="invalid lbl lbl-red hide" id="confirm-invalid">确认密码不匹配</span>
    </p>
    <p class="field">
        <label>&nbsp;</label>
        <button class="btn btn-blue">保存修改</button>
    </p>
</form>
<script>
    $(function(){
        new FormValidator("password-form",[
            {"name":"old","rules":"min_length[2]|max_length[20]"},
            {"name":"new","rules":"min_length[2]|max_length[20]"},
            {"name":"confirm","rules":"required|matches[new]"}
        ],function(errors,e){
            e.preventDefault();
            $('.invalid').hide();
            if(errors.length){
                $("#"+errors[0].id+"-invalid").removeClass("hide").show();
                return;
            }
            $('#password').ajaxSubmit(function(json){
                if(!json.res){
                    alert(json.msg);
                }else{
                    alert("已保存");
                }
            });
        })
    });
</script>